package org.mch.func.db.pdmfile;

public class PdmTypeConvert {

	public static final String getJavaType(String dbtype, Integer length, Integer precision) {
		if ((dbtype == null) || (dbtype.trim().equals(""))) {
			return null;
		}

		dbtype = dbtype.toLowerCase();

		if ("decimal".equals(dbtype)) {
			if ((precision != null) && (precision.intValue() > 0))
				return "Double";
			if (length.intValue() > 10) {
				return "Long";
			}
			return "Integer";
		}

		if ("number".equals(dbtype)) {
			if ((precision != null) && (precision.intValue() > 0))
				return "Double";
			if (length.intValue() > 10) {
				return "Long";
			}
			return "Integer";
		}

		if (PdmTypeMap.PdmTypeJavaTypeMap.containsKey(dbtype)) {
			return (String) PdmTypeMap.PdmTypeJavaTypeMap.get(dbtype);
		}
		return null;
	}

	public static final String getNCJavaType(String dbtype, Integer length, Integer precision) {
		if ((dbtype == null) || (dbtype.trim().equals(""))) {
			return null;
		}

		dbtype = dbtype.toLowerCase();

		if ("decimal".equals(dbtype)) {
			if ((precision != null) && (precision.intValue() > 0))
				return "UFDouble";
			if (length.intValue() > 10) {
				return "Long";
			}
			return "Integer";
		}

		if ("number".equals(dbtype)) {
			if ((precision != null) && (precision.intValue() > 0))
				return "UFDouble";
			if (length.intValue() > 10) {
				return "Long";
			}
			return "Integer";
		}

		if ("char".equals(dbtype)) {
			if (length.intValue() == 10)
				return "UFDate";
			if (length.intValue() == 19)
				return "UFDateTime";
			if (length.intValue() == 8) {
				return "UFTime";
			}
			return "String";
		}

		if (PdmTypeMap.NcPdmTypeJavaTypeMap.containsKey(dbtype)) {
			return (String) PdmTypeMap.NcPdmTypeJavaTypeMap.get(dbtype);
		}
		return null;
	}
}